﻿using System;

namespace Dubbo.Rpc
{
    public sealed class RpcException : Exception
    {
        public static readonly int UNKNOWN_EXCEPTION = 0;

        public static readonly int NETWORK_EXCEPTION = 1;

        public static readonly int TIMEOUT_EXCEPTION = 2;

        public static readonly int BIZ_EXCEPTION = 3;

        public static readonly int FORBIDDEN_EXCEPTION = 4;

        public static readonly int SERIALIZATION_EXCEPTION = 5;

        private int code; // RpcException不能有子类，异常类型用ErrorCode表示，以便保持兼容。

        public RpcException()
        {
        }

        public RpcException(string message)
            : base(message)
        {
        }

        public RpcException(string message, Exception innerException)
            : base(message, innerException)
        {
        }
        

        public bool isForbidded()
        {
            return code == FORBIDDEN_EXCEPTION;
        }

        public bool isTimeout()
        {
            return code == TIMEOUT_EXCEPTION;
        }

        public bool isNetwork()
        {
            return code == NETWORK_EXCEPTION;
        }

        public bool isSerialization()
        {
            return code == SERIALIZATION_EXCEPTION;
        }
    }
}
